package com.java2207.group1.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.java2207.group1.common.LayuiPageVo;
import com.java2207.group1.mapper.DormMapper;
import com.java2207.group1.pojo.Dorm;
import com.java2207.group1.service.DormService;
import com.java2207.group1.vo.Breakfast.BarVo;
import com.java2207.group1.vo.Breakfast.PieVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author :xs
 * @date : 2022/7/26
 */
@Service("dormService")
public class DormServiceImpl implements DormService {

    @Autowired
    private DormMapper dormMapper;

    @Override
    public LayuiPageVo<Dorm> dormPage(Map<String, Object> params) {
        int page = Integer.parseInt(params.get("page") + "");
        int limit = Integer.parseInt(params.get("limit") + "");
        PageHelper.startPage(page, limit);
        List<Dorm> dorms = dormMapper.dormPageData(params);
        //mybatis的分页数据结构
        PageInfo<Dorm> dormPageInfo = new PageInfo<>(dorms);
        LayuiPageVo<Dorm> dormLayuiPageVo = new LayuiPageVo<>();
        dormLayuiPageVo.setCode(0);
        dormLayuiPageVo.setMsg("分页列表数据");
        dormLayuiPageVo.setCount(dormPageInfo.getTotal());
        dormLayuiPageVo.setData(dormPageInfo.getList());



        return dormLayuiPageVo;
    }

    @Override
    public int deleteDorm(Integer id) {
        int i = dormMapper.deleteDorm(id);
        return i;
    }

    @Override
    public int deleteDormsById(String ids) {
      int i = dormMapper.deleteDormsByIds(ids);
        return i;
    }

    @Override
    public int addDorm(Dorm dorm) {
    int i = dormMapper.addDorm(dorm);
        return i;
    }

    @Override
    public int updateDorm(Dorm dorm) {
        int i = dormMapper.updateDorm(dorm);
        return i;
    }

    @Override
    public List<PieVo> TypeNameData() {
       List<PieVo>list = dormMapper.TypoNamePieData();
        return list;
    }

    @Override
    public List<BarVo> TypeNameBarData() {
        List<BarVo>list = dormMapper.TypeNameBarDate();
        return list;
    }
}
